<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='ffbh'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="cardNo" value="${params.cardNo}" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='gwkmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" value="${params.name}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='zt'/></label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <option value="1"
                                        <c:if test="${params.status == 1}">selected</c:if> ><fmt:message key='yxj'/>
                                </option>
                                <option value="2"
                                        <c:if test="${params.status == 2}">selected</c:if> ><fmt:message key='ysj'/>
                                </option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='sj'/></label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input" style="width: 100px" name="startTime" value="${params.startTime}">
                            <span class="layui-inline">-</span>
                            <input type="text" class="layui-input" style="width: 100px" name="endTime" value="${params.endTime}">
                        </div>
                    </div>

                    <!-- 需要排序的字段 -->
                    <%--                    <input type="hidden" class="feijin-orderby" name="orderByCreateTime" id="orderByCreateTimeParams" value="${params.orderByCreateTime}"/>--%>
                    <!-- 需要排序的字段 -->

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <%--            <shiro:hasPermission name="member:export">--%>
            <%--                <a href="${web_domain}/mall/marketing/shoppingCard?username=${params.username}&realName=${params.realName}&nickname=${params.nickname}&orderByCreateTime=${params.orderByCreateTime}" class="layui-btn layui-btn-sm" id="export"><i class="layui-icon">&#xe601;</i> 导出会员</a>--%>
            <%--            </shiro:hasPermission>--%>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="feijin-add"><i class="layui-icon layui-icon-add-circle"></i> <fmt:message key='xzgwk'/></a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="enables"><i class="layui-icon">&#xe605;</i> <fmt:message key='plsj'/></a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="disables"><i class="layui-icon">&#x1006;</i> <fmt:message key='plxj'/></a>

            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                    <th><fmt:message key='ffbh'/></th>
                    <th><fmt:message key='gwkmc'/></th>
                    <th><fmt:message key='mz'/></th>
                    <th><fmt:message key='sj2'/></th>
                    <th><fmt:message key='gwksl'/></th>
                    <th><fmt:message key='yxq'/></th>
                    <th><fmt:message key='xszsl'/></th>
                    <th><fmt:message key='xszje'/></th>
                    <th><fmt:message key='cjsj'/></th>
                    <th><fmt:message key='zt'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${item.cardNo}</td>
                        <td>${item.name}</td>
                        <td><fmt:formatNumber value="${item.faceValue}" type="CURRENCY"/></td>
                        <td><fmt:formatNumber value="${item.price}" type="CURRENCY"/></td>
                        <td>${item.number}</td>
                        <td>
                            <c:if test="${item.validType == 1}">
                                <fmt:formatDate value="${item.validStartTime}" pattern="yyyy-MM-dd HH:mm"/> -
                                <fmt:formatDate value="${item.validEndTime}" pattern="yyyy-MM-dd HH:mm"/>
                            </c:if>
                            <c:if test="${item.validType == 2}"><fmt:message key='lqh'/>${item.validDays}<fmt:message key='tnksy'/></c:if>
                        </td>
                        <td>${item.saleNumberCount}</td>
                        <td><fmt:formatNumber value="${item.price * item.saleNumberCount}" type="CURRENCY"/></td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status == 1}"><b><fmt:message key='yxj'/></b></c:when>
                                <c:otherwise><b style="color:red;"><fmt:message key='ysj'/></b></c:otherwise>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ckxq'/></a>
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-record"><fmt:message key='ffjl'/></a>
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs present"><fmt:message key='zsgwk'/></a>
                                <c:choose>
                                    <c:when test="${item.status == 2}">
                                        <shiro:hasPermission name="shoppingcard:disable">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disable"><fmt:message key='xj'/></a>
                                        </shiro:hasPermission>
                                    </c:when>
                                    <c:otherwise>
                                        <shiro:hasPermission name="shoppingcard:enable">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-enable"><fmt:message key='sj'/></a>
                                        </shiro:hasPermission>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    layui.use(['layer'], function () {
        var layer = layui.layer;

        /**
         * 添加购物卡
         */
        $("#feijin-add").click(function () {
            layer.open({
                type: 2,
                title: '<fmt:message key='tjgwk'/>',
                content: '${web_domain}/mall/marketing/shoppingCard/create',
                maxmin: true,
                area: ['95%', '95%'],
                btn: ['<fmt:message key='qd'/>', '<fmt:message key='qx'/>'],
                yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        /**
         * 赠送购物卡
         */
        $(".present").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                title: '<fmt:message key='zsgwk'/>',
                content: '${web_domain}/mall/marketing/shoppingCard/present/' + id,
                maxmin: true,
                area: ['70%', '60%'],
                btn: ['<fmt:message key='qd'/>', '<fmt:message key='fh'/>'],
                yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        /**
         * 批量上架
         */
        $("#enables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qbsjm?'/>',
                btn: ['<fmt:message key='sj'/>', '<fmt:message key='qx'/>'],
                yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/mall/marketing/shoppingCard/enables",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";")
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        /**
         * 批量下架
         */
        $("#disables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qbxjm?'/>',
                btn: ['<fmt:message key='xj'/>', '<fmt:message key='qx'/>'],
                yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/mall/marketing/shoppingCard/disables",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";")
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        /**
         * 下架
         */
        $(".feijin-disable").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='xj'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrxjm?'/></span>',
                    btn: ['<fmt:message key='qd'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/marketing/shoppingCard/" + id + "/disable",
                            success: function () {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        /**
         * 上架
         */
        $(".feijin-enable").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='sj'/>',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrsjm?'/></span>',
                    btn: ['<fmt:message key='qy'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/marketing/shoppingCard/" + id + "/enable",
                            success: function () {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        /**
         * 查看详情
         */
        $(".feijin-detail").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                title: '<fmt:message key='gwkxq'/>',
                content: '${web_domain}/mall/marketing/shoppingCard/' + id + "/detail",
                maxmin: true,
                area: ['95%', '95%'],
                btn: ['<fmt:message key='gb'/>']
            });
        });

        /**
         * 发放记录
         */
        $(".feijin-record").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                title: '<fmt:message key='ffjl'/>',
                content: '${web_domain}/mall/marketing/shoppingCard/' + id + "/record",
                maxmin: true,
                area: ['95%', '95%'],
                btn: ['<fmt:message key='gb'/>']
            });
        });

    });


    $("#checkboxs").click(function () {
        if (this.checked) {
            $(".feijin-check:checkbox").prop("checked", true);
        } else {
            $(".feijin-check:checkbox").prop("checked", false);
        }
    });

</script>
</body>
</fmt:bundle>
</html>
